<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class ConvertDateHelper{
    
     //FORMAT DEFAULT TIME d/m/Y
    public function explode_datetime_iso($delimiter, $field_name, $type="datetime") 
    { //UNTUK SAVE KE DBASE ATAU UNTUK MEMBALIKKAN NILAI DARI DBASE
        $register_delimiter = array('/' => '-', '-' => '/');
    
        if (is_array($register_delimiter)) 
        {
            foreach ($register_delimiter as $key => $val) 
            {
                if ($key == $delimiter) 
                {
                    $format = $val;
                } else 
                {
                    $format = '-'; //SET DEFAULT JIKA DATA TIDAK KETEMU
                }
            }
        }



        $explode_date_arr = explode($delimiter, $field_name);

        $replace_year = str_replace(' ', ':', $explode_date_arr[2]);
        $explode_time_arr = explode(':', $replace_year);
        
        $get_time=($type=='datetime')?$explode_time_arr[1] . ':' . $explode_time_arr[2] . ':' . $explode_time_arr[3]:'';
        $get_datetime = $explode_time_arr[0] . $format . $explode_date_arr[1] . $format . $explode_date_arr[0] . ' ' . $get_time;

        return $get_datetime;
    }
}

?>
